package joc.systemtest.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;

public class DummyAppender extends AppenderSkeleton {
	private List<String> messages = new ArrayList<String>();

	public DummyAppender(Class<?> clazz) {
		Logger.getLogger(clazz).addAppender(this);
		Logger.getLogger(clazz).setLevel(Level.ALL);
	}

	@Override
	protected void append(LoggingEvent event) {
		messages.add(event.getMessage().toString());
	}

	@Override
	public void close() {
	}

	@Override
	public boolean requiresLayout() {
		return false;
	}

	public List<String> getMessages() {
		return messages;
	}

	public void clear() {
		messages.clear();
	}

	public String getLastMessage() {
		return messages.get(messages.size() - 1);
	}

}
